/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aicue1.callbackhandlers;

import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.ws.security.WSPasswordCallback;


/**
 *
 * @author Thomas
 */
public class ServerPasswordCallbackHandler implements CallbackHandler {

    private String username = "greatUsername";
    private String password = "greatPassword";

    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

        WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
        if (pc.getIdentifier().equals(username) && pc.getPassword().equals(password))
            System.out.println(pc.getIdentifier() + " has been authorized.");
        else
            throw new IOException("Username and password don't match.");
    }
}